package com.zunipe.until;

import com.zunipe.ZunipeTools;
import com.zunipe.screen.AutoAttackOptionScreen;
import com.zunipe.screen.ScanningBoxOptionScreen;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.regex.Pattern;

public class Util
{
    public static boolean xrayOn = false;
    public volatile static int xrayRange = 32;
    public volatile static boolean autoEat = false;
    public volatile static boolean autoAttack = false;
    public volatile static boolean autoDrop = false;
    public static boolean firstLogin = true;
    public volatile static boolean alwaysBackwardWalk = false;
    public volatile static boolean autoClickLeft = false;
    public volatile static boolean autoClickRight = false;
    public volatile static boolean scanningBox = false;
    public volatile static boolean autoSignIn = false;
    public static boolean autoRedPacket = false;
    public volatile static int clickLeftInterval = 300;
    public volatile static int clickRightInterval = 300;
    public volatile static int yawScope = 10;
    public volatile static int pitchScope = 10;
    public volatile static int xrayScanningInterval = 1000;
    public static String username = "";
    public static String accessToken = "";
    public static String uuid = "";
    public volatile static int tick = 300;
    public volatile static double detectDistance = 5.0;
    public static boolean openNightVision = false;
    public static AutoAttackOptionScreen.AttackTarget attackTarget = AutoAttackOptionScreen.AttackTarget.MONSTER;
    public static AutoAttackOptionScreen.AttackMode attackMode = AutoAttackOptionScreen.AttackMode.LEFT;
    public static ScanningBoxOptionScreen.ScanningMode scanningMode = ScanningBoxOptionScreen.ScanningMode.BACKWARD;
    private static final String[] items = {"宝石", "矿工", "雷神", "死亡", "死神", "闪避", "折", "海洋之心", "下界合金碎片", "下界合金锭", "下界合金块", "胆", "兑换券",
            "神奇", "幸运鱼竿", "骇客代码", "刷怪笼", "史诗", "放置", "振奋", "无尽之刃", "饮血之刃", "红石矿石", "铁矿石", "金矿石", "青金石矿石", "潜影盒"};
    public static final Set<String> itemList = new HashSet<>(List.of(items));
    public static final Set<String> exclusionItemList = new HashSet<>();

    public static final Set<String> whiteList = new HashSet<>();

    public static void getURLData(String Url, String coding)
    {
        try
        {
            URL url = new URL(Url);
            HttpURLConnection huc = (HttpURLConnection) url.openConnection();
            huc.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

            InputStream is = huc.getInputStream();

            BufferedReader r = new BufferedReader(new InputStreamReader(is, coding));
            String line;
            ZunipeTools.LOGGER.info(MinecraftClient.getInstance().getSession().getUsername() + " Pass");
            while ((line = r.readLine()) != null)
            {
                whiteList.add(line);
                if (line.equals(MinecraftClient.getInstance().getSession().getUsername()))
                    ZunipeTools.PASS = true;
            }
        } catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }
    public static int randomInt(int min, int max)
    {
        return new Random().nextInt(max) % (max - min + 1) + min;
    }

    public enum Switch
    {
        OPEN("开启", true), CLOSE("关闭", false);

        private final String name;
        private final boolean sw;

        Switch(String name, boolean sw)
        {
            this.name = name;
            this.sw = sw;
        }

        public static Switch get(boolean b)
        {
            return b ? OPEN : CLOSE;
        }

        public boolean getSwitch()
        {
            return sw;
        }

        public Text getTranslatableName()
        {
            return new LiteralText(this.name);
        }
    }
}
